package com.cxh.mchat.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author cxh
 * @date 2021/12/28 18:10
 **/
@Configuration
public class ResourcesConfig implements WebMvcConfigurer {
    /**
     * 文件配置
     */
    @Resource
    private FileProperties properties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry)
    {
        FileProperties.ElPath path = properties.getPath();
        String avatarUtl = "file:" + path.getAvatar().replace("\\", "/");
        String pathUtl = "file:" + path.getPath().replace("\\", "/");
        registry.addResourceHandler("/avatar/**").addResourceLocations(avatarUtl).setCachePeriod(0);
        registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0);
    }
}
